<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>流程定义总数</span>
              <el-icon><Files /></el-icon>
            </div>
          </template>
          <div class="card-content">
            <div class="data-value">{{ stats.processDefinitions }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>流程实例总数</span>
              <el-icon><Operation /></el-icon>
            </div>
          </template>
          <div class="card-content">
            <div class="data-value">{{ stats.processInstances }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>待办任务总数</span>
              <el-icon><List /></el-icon>
            </div>
          </template>
          <div class="card-content">
            <div class="data-value">{{ stats.tasks }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>历史流程总数</span>
              <el-icon><Histogram /></el-icon>
            </div>
          </template>
          <div class="card-content">
            <div class="data-value">{{ stats.historyProcesses }}</div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" style="margin-top: 20px;">
      <el-col :span="12">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>流程执行情况</span>
            </div>
          </template>
          <div class="chart-container">
            <div class="placeholder-chart">流程执行统计图表</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>任务完成情况</span>
            </div>
          </template>
          <div class="chart-container">
            <div class="placeholder-chart">任务完成统计图表</div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-card shadow="hover" style="margin-top: 20px;">
      <template #header>
        <div class="card-header">
          <span>最近流程活动</span>
        </div>
      </template>
      <el-table :data="recentActivities" style="width: 100%">
        <el-table-column prop="processName" label="流程名称" />
        <el-table-column prop="activityName" label="活动名称" />
        <el-table-column prop="assignee" label="处理人" />
        <el-table-column prop="startTime" label="开始时间" />
        <el-table-column prop="endTime" label="结束时间" />
        <el-table-column prop="duration" label="耗时" />
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { dashboardApi } from '@/api/flowable'

// 统计数据
const stats = ref({
  processDefinitions: 0,
  processInstances: 0,
  tasks: 0,
  historyProcesses: 0
})

// 最近活动数据
const recentActivities = ref([])

// 获取数据
const fetchData = async () => {
  try {
    // 获取统计数据
    const statsRes = await dashboardApi.getStats()
    stats.value = statsRes.data
    
    // 获取最近活动
    const activitiesRes = await dashboardApi.getActivities()
    recentActivities.value = activitiesRes.data
  } catch (error) {
    console.error('获取仪表盘数据失败', error)
  }
}

onMounted(() => {
  fetchData()
})
</script>

<style scoped>
.dashboard {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.data-card {
  height: 120px;
}

.card-content {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}

.data-value {
  font-size: 28px;
  font-weight: bold;
  color: #409EFF;
}

.chart-container {
  height: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.placeholder-chart {
  color: #909399;
  font-size: 16px;
  border: 1px dashed #d9d9d9;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style> 